<?php

namespace controller;

class MasterController{
	private $adminController;
	private $bloggController;
	private $homeController;
	private $adminView;
	private $navigationView;
	
	//Tar in bloggDAL här för att kunna använda den i admin-&bloggcontroller
	public function __construct($bloggDAL){
		$adminHandler = new \handler\AdminHandler($bloggDAL);
		$this->adminController = new \controller\AdminController($adminHandler) ;
		$this->bloggController = new \controller\BloggController($adminHandler);
		$this->homeController = new \controller\HomeController();
		$this->adminView = new \view\AdminView();
		$this->navigationView = new \view\NavigationView();
	}
	
	public function doControll(){

		//Gör en varabel för activcontroller
		$activeController = $this->navigationView->getActiveController();
		
		//Är HomeController aktiv?
		if($activeController === \view\NavigationView::HomeController){
			$content = $this->homeController->homeControllerDoControll();
		}
		//Är BloggController aktiv?
		else if($activeController === \view\NavigationView::BloggController){
			$content = $this->bloggController->bloggControllerDoControll();
		}
		//Är AdminController aktiv?
		else if($activeController === \view\NavigationView::AdminController){
			$content = $this->adminController->adminControllerDoControll();
		}
		//Om ingen controller är aktiv ska homeController visas
		else{
			$content = $this->homeController->homeControllerDoControll();
		}
		$pcv = new \view\PageCompositionView();
		$ret = $pcv->getBloggViewPage($content);
		
		
		return $ret;
	}
	
}
